//
//  HeadCollectionCell.m
//  TourPlay
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 王军岐. All rights reserved.
//

#import "HeadCollectionCell.h"

#import "HeadCollectionViewCell.h"

@interface HeadCollectionCell () <UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UICollectionView *headCollectionV;

@end



@implementation HeadCollectionCell
- (void)dealloc
{
    [_headCollectionV release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews
{
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置每个item(cell)的大小
    flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH / 4.f, 110.f * AUTOSCREEN_HEIGHT);
    // 设置最小行间距
    flowLayout.minimumLineSpacing = 0;
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    // 滚动方向
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.headCollectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 110.f * AUTOSCREEN_HEIGHT) collectionViewLayout:flowLayout];
    self.headCollectionV.delegate = self;
    self.headCollectionV.dataSource = self;
    // 分页滚动
    self.headCollectionV.pagingEnabled = YES;
    // 隐藏滑动条
    self.headCollectionV.showsHorizontalScrollIndicator = NO;
    
    self.headCollectionV.backgroundColor = [UIColor clearColor];
    [self.headCollectionV registerClass:[HeadCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self.contentView addSubview:self.headCollectionV];
    [_headCollectionV release];
    [flowLayout release];

}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 4;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *celllStr = @"cell";
    HeadCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:celllStr forIndexPath:indexPath];
    
    [cell setNSIndexPath:indexPath];


    cell.backgroundColor = [UIColor clearColor];

    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%ld", indexPath.row);
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
